package com.dr.service.impl;

import com.dr.Enum.ExcepEnum;
import com.dr.db.SysUserMapper;
import com.dr.exception.ServiceExcep;
import com.dr.pojo.SysUser;
import com.dr.service.SysLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by tugou on 2017/4/23.
 */
@Service
public class SysLoginServiceImpl implements SysLoginService {

    @Autowired
    SysUserMapper SysUserMapper;

    @Override
    public SysUser getSysUserByLoginInfo(SysUser sysUser) throws ServiceExcep{
        SysUser user = SysUserMapper.getSysUser(sysUser);
        if (user == null){
            throw new ServiceExcep(ExcepEnum.QUERYRESULTISEMPTY.getName(),ExcepEnum.QUERYRESULTISEMPTY.getIndex());
        }
        return user;
    }

    @Override
    public void saveSysUser(SysUser user)throws ServiceExcep{
        int result = SysUserMapper.insertSysUser(user);
        if(result == 0){
            throw new ServiceExcep(ExcepEnum.INSERTDATAEMPTY.getName(),ExcepEnum.INSERTDATAEMPTY.getIndex());
        }
    }
}
